#include "VRPObjects.h"
#include <QDebug>

/// Start Depo implementation
Depo::Depo(VRPRouteGraphTraits::Graph& graph, VRPRouteGraphTraits::Vertex vertex)
    :graph_(graph), vertex_(vertex)
{
}

Depo::~Depo()
{
}

CirclePointPtr Depo::getCoordinate()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
        return VRPRouteGraphTraits::GetVertexCoordinateMap(graph_)[vertex_];
    return CirclePointPtr();
}

/// End Depo inplementation

/// Start Customer implementation
Customer::Customer(VRPRouteGraphTraits::Graph& graph, VRPRouteGraphTraits::Vertex vertex)
    :graph_(graph), vertex_(vertex)
{
}

Customer::~Customer()
{
    qDebug()<<"Delete customer";
}

CirclePointPtr Customer::getCoordinate()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
        return VRPRouteGraphTraits::GetVertexCoordinateMap(graph_)[vertex_];
    return CirclePointPtr();
}

QString Customer::getName()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
        return QString::fromStdString(VRPRouteGraphTraits::GetVertexNameMap(graph_)[vertex_]);
    return QString();
}

LineStringPtr Customer::getDepoRoute()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
    {
        std::pair<VRPRouteGraphTraits::VertexIterator, VRPRouteGraphTraits::VertexIterator> vp;
        vp = boost::vertices(graph_);

        VRPRouteGraphTraits::Edge depoEdge = boost::edge(*vp.first, vertex_, graph_).first;
        LineStringPtr ls = VRPRouteGraphTraits::GetEdgeRouteMap(graph_)[depoEdge];
        //qDebug()<<ls->name();

        return ls;
    }
    return LineStringPtr();
}

int Customer::getDemand()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
        return VRPRouteGraphTraits::GetVertexDemandMap(graph_)[vertex_];
    return 0;
}

bool Customer::getType()
{
    if(vertex_ != VRPRouteGraphTraits::null_vertex())
        return VRPRouteGraphTraits::GetVertexBackhaulMap(graph_)[vertex_];
    return 0;
}

/// End Customer implementation
Vehicle::Vehicle(const QString &name, quint32 capacity, quint32 cost)
    :name_(name), capacity_(capacity), cost_(cost)
{
}

Vehicle::~Vehicle()
{
}

QString Vehicle::name()
{
    return name_;
}

void Vehicle::setName(const QString &name)
{
    name_ = name;
}

quint32 Vehicle::capacity()
{
    return capacity_;
}

void Vehicle::setCapacity(quint32 capacity)
{
    capacity_ = capacity;
}

quint32 Vehicle::cost()
{
    return cost_;
}

void Vehicle::setCost(quint32 cost)
{
    cost_ = cost;
}

VRPPixmapsFactory* VRPPixmapsFactory::inst_ = NULL;

VRPPixmapsFactory::VRPPixmapsFactory()
{
    routePen_ = new QPen(QColor(0, 0, 255));
    routePen_->setWidth(5);
}

VRPPixmapsFactory::~VRPPixmapsFactory()
{
    delete depoPixmap_;
    delete customerPixmap_;
}

VRPPixmapsFactory* VRPPixmapsFactory::instance()
{
    if(!inst_)
        inst_ = new VRPPixmapsFactory();
    return inst_;
}

QPixmap* VRPPixmapsFactory::createdDepoPixmap()
{
    return new QPixmap(":/Resources/images/building.png");;
}

QPixmap* VRPPixmapsFactory::createCustomerPixmap()
{
    return new QPixmap(":/Resources/images/home.png");
}

QPen* VRPPixmapsFactory::routePen()
{
    return routePen_;
}
